from django.db import models


class DailyProjectStats(models.Model):
    day = models.DateField()
    region = models.CharField(max_length=100, blank=True)
    city = models.CharField(max_length=100, blank=True)
    project_type = models.CharField(max_length=100, blank=True)
    industry = models.CharField(max_length=100, blank=True)
    project_count = models.IntegerField(default=0)

    class Meta:
        db_table = 'an_daily_project_stats'
        indexes = [
            models.Index(fields=['day']),
            models.Index(fields=['region']),
            models.Index(fields=['city']),
            models.Index(fields=['project_type']),
            models.Index(fields=['industry']),
        ]


class IndustryConcentration(models.Model):
    period = models.CharField(max_length=20)  # e.g., '2025-11'
    region = models.CharField(max_length=100, blank=True)
    city = models.CharField(max_length=100, blank=True)
    industry = models.CharField(max_length=100, blank=True)
    hhi = models.FloatField(default=0.0)
    top_share = models.FloatField(default=0.0)

    class Meta:
        db_table = 'an_industry_concentration'
        indexes = [
            models.Index(fields=['period']),
            models.Index(fields=['region']),
            models.Index(fields=['city']),
            models.Index(fields=['industry']),
        ]


class CompanyWinStats(models.Model):
    period = models.CharField(max_length=20)
    region = models.CharField(max_length=100, blank=True)
    city = models.CharField(max_length=100, blank=True)
    industry = models.CharField(max_length=100, blank=True)
    company_id = models.IntegerField()
    bid_count = models.IntegerField(default=0)
    win_count = models.IntegerField(default=0)
    win_rate = models.FloatField(default=0.0)

    class Meta:
        db_table = 'an_company_win_stats'
        indexes = [
            models.Index(fields=['period']),
            models.Index(fields=['region']),
            models.Index(fields=['city']),
            models.Index(fields=['industry']),
            models.Index(fields=['company_id']),
        ]


class AmountBucketStats(models.Model):
    period = models.CharField(max_length=20)
    source = models.CharField(max_length=20)  # budget or winning
    region = models.CharField(max_length=100, blank=True)
    city = models.CharField(max_length=100, blank=True)
    industry = models.CharField(max_length=100, blank=True)
    bucket = models.CharField(max_length=50)
    count = models.IntegerField(default=0)
    total = models.FloatField(default=0.0)

    class Meta:
        db_table = 'an_amount_bucket_stats'
        indexes = [
            models.Index(fields=['period']),
            models.Index(fields=['source']),
            models.Index(fields=['region']),
            models.Index(fields=['city']),
            models.Index(fields=['industry']),
            models.Index(fields=['bucket']),
        ]
